import { PlayerHeadUI } from "../gameEtc/PlayerHeadUI"
import { PlayerOwnModel } from "./PlayerOwnModel"

@Component
export default class Appearance extends PlayerOwnModel{
    static AppearanceMap:Map<number,Appearance> = new Map()

    static onOwnerPlayerRankChanged:Action = new Action()

    @mw.Property({multicast:true, replicated:true, onChanged:'onOwnerPlayerNameChanged'})
    playerName:string
    @mw.Property({multicast:true, replicated:true, onChanged:'onOwnerPlayerRankChanged'})
    playerRank:number

    ownerPlayer:Player
    weaponGameObject: mw.GameObject
    headUI:PlayerHeadUI
    pole: mw.GameObject

    init(ownerPlayerID:number){
        this.ownerPlayerID = ownerPlayerID
        Appearance.AppearanceMap.set(this.ownerPlayerID, this)
    }

    protected onOwnerPlayerIDChanged(){
        Appearance.AppearanceMap.set(this.ownerPlayerID, this)
    }

    private onOwnerPlayerNameChanged(){
        
    }

    private onOwnerPlayerRankChanged(){
        Appearance.onOwnerPlayerRankChanged.call()
    }

    protected onDestroy(): void {
        if(SystemUtil.isClient()) {
            GameObjPool.despawn(this.weaponGameObject)
        }
        Appearance.AppearanceMap.delete(this.ownerPlayerID)
    }
}